<?php
  include('db_connect.php');
  
  $frm = $_POST;
  $ses = $_SESSION;
  
  //check if username exists
  if(isset($frm['send']))
  {
    if($frm['send'] == 'Login'){
      $username_input = $frm['username'];
      $password = md5($frm['password']);
      
      $log_info_fetch_query = mysql_query('SELECT gebruikers_naam, wachtwoord FROM USERNAME WHERE gebruikers_naam = "' . $username_input . '"') or die(mysql_error());
    
      while($log_row = mysql_fetch_array($log_info_fetch_query))
      {
         if($username_input == $log_row['gebruikers_naam'])
          {
            $username = $log_row['gebruikers_naam'];
          }
          if($password == $log_row['wachtwoord'])
          {
             if(isset($ses['logged']))
             {
               $ses['logged'] = true;
             }
             else
             {
               $ses['logged'] = true;
             }
             if(isset($ses['username']))
             {
                $ses['username'];
             }
             else
             {
                $ses['username'] = $username;
             }
             if(isset($ses['password']))
             {
                $ses['password'];
             }
             else
             {
                $ses['password'] = $password;
             }
          }
      }
    }
  }
  if(isset($frm['logout']))
  {
    if($frm['logout'] == 'Uitloggen')
    {
      session_destroy();
    }
  }
?>                                      